package br.com.linkcom.sined.util.tag;

import java.text.SimpleDateFormat;
import java.util.Date;

import br.com.linkcom.neo.controller.crud.FiltroListagem;
import br.com.linkcom.neo.core.web.NeoWeb;
import br.com.linkcom.neo.util.Util;
import br.com.linkcom.sined.geral.service.TelaService;


public class TagFunctions {
	
	public static String truncate(String texto,Integer size) {
		if(texto != null && texto.length() >= size)
			texto = texto.substring(0, size)+" ...";
		
		return texto;
	}

	public static String getTelaDescricao() {
		return TelaService.getInstance().getTelaDescriptionByUrl(getPartialURL());
	}
	
	public static String getPartialURL(){
		return Util.web.getFirstUrl();
	}
	
	public static String getTotalPage(FiltroListagem filtro){
		if((filtro.getCurrentPage() + 1) == filtro.getNumberOfPages())
			return String.valueOf(filtro.getNumberOfResults());
		else
			return String.valueOf((filtro.getCurrentPage() + 1) * filtro.getPageSize());
	}
	
	public static Boolean getModuloPermissao(String path){
		return true;
	}
	
	public static String findUserByCd(Integer code){
		return null;
	}
	
	public static String formataData(Date data){
		if(data!=null)
		{
			return new SimpleDateFormat("dd/MM/yyyy HH:mm").format(data);
		}
		else
		{
			return "";
		}
	}
	
	public static String formataDataDia(Date data){
		if(data!=null)
		{
			return new SimpleDateFormat("dd/MM/yyyy").format(data);
		}
		else
		{
			return "";
		}
	}
	
	
	public static String getContextPath(){
		return NeoWeb.getRequestContext().getServletRequest().getContextPath();
	}
	
	public static String getBgColor(){
		String contextPath = NeoWeb.getRequestContext().getServletRequest().getContextPath();
		
		if(contextPath.contains("teste") && !contextPath.contains("cleber"))
			return "red";
		
		return "";
	}
	
	public static String getOrigemCadastro(Object object){
		return null;
	}
}